package org.offsync.rich

import org.offsync.async.ReadSelector
import java.nio.channels.SocketChannel
import org.offsync.async.WriteSelector
import org.offsync.async.AsyncReturn

class RichSocketChannel(val channel: SocketChannel) {
  def onReady(
      readSelector: ReadSelector)(
          f: () => Unit) = {
    readSelector.invoke { () =>
      channel.register(readSelector.selector, readSelector.op, f)
    }
  }

  def onReady(
      writeSelector: WriteSelector)(
          f: () => Unit): AsyncReturn = {
    writeSelector.invoke { () =>
      channel.register(writeSelector.selector, writeSelector.op, f)
    }
  }
}
